package com.csot.ry.service.impl;

import cn.hutool.core.net.NetUtil;
import cn.hutool.core.util.StrUtil;
import com.csot.ry.domain.TIpSegmentHistory;
import com.csot.ry.mapper.TIpSegmentHistoryMapper;
import com.csot.ry.service.ITIpSegmentHistoryService;
import com.csot.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 历史信息查询Service业务层处理
 * 
 * @author 刘沙
 * @date 2022-06-01
 */
@Service
public class TIpSegmentHistoryServiceImpl implements ITIpSegmentHistoryService {
	@Autowired
	private TIpSegmentHistoryMapper tIpSegmentHistoryMapper;

	/**
	 * 查询历史信息查询
	 * 
	 * @param id 历史信息查询主键
	 * @return 历史信息查询
	 */
	@Override
	public TIpSegmentHistory selectTIpSegmentHistoryById(Long id) {
		return tIpSegmentHistoryMapper.selectTIpSegmentHistoryById(id);
	}

	/**
	 * 查询历史信息查询列表
	 * 
	 * @param tIpSegmentHistory 历史信息查询
	 * @return 历史信息查询
	 */
	@Override
	public List<TIpSegmentHistory> selectTIpSegmentHistoryList(TIpSegmentHistory tIpSegmentHistory) {
//		if (Objects.isNull(tIpSegmentHistory) || Objects.isNull(tIpSegmentHistory.getIpStart()))
		if(StrUtil.isNotEmpty(tIpSegmentHistory.getIpStart())) {
			tIpSegmentHistory.setIpStartI(NetUtil.ipv4ToLong(tIpSegmentHistory.getIpStart()));
		}
		if(StrUtil.isNotEmpty(tIpSegmentHistory.getIpEnd())) {
			tIpSegmentHistory.setIpEndI(NetUtil.ipv4ToLong(tIpSegmentHistory.getIpEnd()));
		}
		return tIpSegmentHistoryMapper.selectTIpSegmentHistoryList(tIpSegmentHistory);
//		Long ipAddressbegin = NetUtil.ipv4ToLong(tIpSegmentHistory.getIpStart());
//		Long ipAddressend = NetUtil.ipv4ToLong(tIpSegmentHistory.getIpEnd());
//
//		Long ipAddress = NetUtil.ipv4ToLong(tIpSegmentHistory.getIpStart());
//		List<IpSegmentHistory> rList = new IpSegmentHistory().dao().find(
//				"select * from t_ip_segment_history where ip_start_i >= ? and ip_end_i <= ?", ipAddressbegin, ipAddressend);
//
//		List<TIpSegmentHistory> result = new ArrayList<>();
//		for (IpSegmentHistory r : rList) {
//			TIpSegmentHistory tis = new TIpSegmentHistory();
//			BeanUtils.copyProperties(r, tis);
//			result.add(tis);
//		}
//		return result;
	}

	/**
	 * 新增历史信息查询
	 * 
	 * @param tIpSegmentHistory 历史信息查询
	 * @return 结果
	 */
	@Override
	public int insertTIpSegmentHistory(TIpSegmentHistory tIpSegmentHistory) {
		tIpSegmentHistory.setCreateTime(DateUtils.getNowDate());
		return tIpSegmentHistoryMapper.insertTIpSegmentHistory(tIpSegmentHistory);
	}

	/**
	 * 修改历史信息查询
	 * 
	 * @param tIpSegmentHistory 历史信息查询
	 * @return 结果
	 */
	@Override
	public int updateTIpSegmentHistory(TIpSegmentHistory tIpSegmentHistory) {
		tIpSegmentHistory.setUpdateTime(DateUtils.getNowDate());
		return tIpSegmentHistoryMapper.updateTIpSegmentHistory(tIpSegmentHistory);
	}

	/**
	 * 批量删除历史信息查询
	 * 
	 * @param ids 需要删除的历史信息查询主键
	 * @return 结果
	 */
	@Override
	public int deleteTIpSegmentHistoryByIds(Long[] ids) {
		return tIpSegmentHistoryMapper.deleteTIpSegmentHistoryByIds(ids);
	}

	/**
	 * 删除历史信息查询信息
	 * 
	 * @param id 历史信息查询主键
	 * @return 结果
	 */
	@Override
	public int deleteTIpSegmentHistoryById(Long id) {
		return tIpSegmentHistoryMapper.deleteTIpSegmentHistoryById(id);
	}
}
